package com.cn.hotel.service.impl;

import com.cn.hotel.dao.ICompanyDao;
import com.cn.hotel.dao.Impl.CompanyImpl;
import com.cn.hotel.model.AboutCompanyModel;
import com.cn.hotel.model.CompanyModel;
import com.cn.hotel.service.ICompanyService;
import redis.clients.jedis.Jedis;

import java.util.List;

public class CompanyServiceImpl implements ICompanyService {
    @Override
    public List<CompanyModel> findAll(CompanyModel companyModel) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        return iCompanyDao.findAll(companyModel);
    }

    @Override
    public int getNumber(CompanyModel companyModel) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        return iCompanyDao.getNumber(companyModel);
    }

    @Override
    public CompanyModel findById(Integer temp) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        return iCompanyDao.findById(temp);
    }

    @Override
    public int edit(CompanyModel companyModel) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        int result = iCompanyDao.edit(companyModel);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }

    /**
     * 添加新元素
     * @param companyModel
     * @return
     */
    @Override
    public int add(CompanyModel companyModel) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        int result = iCompanyDao.add(companyModel);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }

    @Override
    public int delete(Integer temp) {
        ICompanyDao iCompanyDao = new CompanyImpl();
        int result = iCompanyDao.delete(temp);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }

    /**
     * 获取关于公司的介绍
     * @return
     */
    @Override
    public AboutCompanyModel getAboutCompanyModel() {
        ICompanyDao iCompanyDao = new CompanyImpl();
        return iCompanyDao.getAboutCompanyModel();
    }
}
